package org.oproject.rmi.hessian.project.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * Herssian的基础配置
 * @see 
 * @author shenqing
 * @since 1.0
 * @version 1.0, Nov 12, 2010 4:50:11 PM
 */
public class BaseConfig
{
	private static Properties configs = new Properties();
	/**
	 * 从新加载配置文件
	 */
	public void reload()
	{
		String path = this.getClass().getResource("/").getPath() + "\\hessian.properties";
		
		FileInputStream is;
		try
		{
			configs.clear();
			
			is = new FileInputStream(path);
			configs.load(is);
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	/**
	 * 是否是通讯安全的，如果是，则返回true;否则返回false
	 * @return
	 */
	public boolean isSecurity()
	{
		String security = configs.getProperty("org.oproject.rmi.hessian.issecurity", "false");
		if(null == security 
				|| security.trim().equals("")
				|| !(security.trim().equals("false") || security.trim().equals("true")))
		{
			security = "false";
		}
		
		if(security.trim().equalsIgnoreCase("false"))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	/**
	 * hessian service接口加载方式
	 * @return
	 */
	public String initType()
	{
		String inittype = configs.getProperty("org.oproject.rmi.hessian.inittype", "file");
		if(null == inittype 
				|| inittype.trim().equals("")
				|| !(inittype.trim().equalsIgnoreCase("db") || inittype.trim().equalsIgnoreCase("file")))
		{
			inittype = "file"; 
		}
		return inittype.trim().toLowerCase();
	}
}
